/*
 * Copyright (c) 2008 Sergey Rudchenko <sergey.rudchenko@gmail.com>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "game.h"
#include "sky.h"
#include "controller.h"
#include "battle_scene.h"

#include <SDL.h>

int init_sdl()
{
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("Failed to init SDL: %s\n", SDL_GetError());
        return 1;
    }

    atexit(SDL_Quit);
    return 0;
}

int main()
{
    if (init_sdl() != 0)
        return 1;

    struct game* ctx = new_game();

    if (!ctx)
        return 1;

    ctx->vid_resx = 640;
    ctx->vid_resy = 480;
    ctx->vid_bpp  = 24;
    ctx->vid_fps  = 30;

    if (game_vid_init(ctx) != 0)
        return 1;

    ctx->global_data = new_sky(ctx);

    struct scene* bs = new_battle_scene(ctx);
    game_push_scene(ctx, bs);

    game_run(ctx);

    game_vid_shutdown(ctx);
    free_sky(ctx->global_data);
    free_game(ctx);

    SDL_Quit();
    return 0;
}

